﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TjZheng.Business;
using TjZheng.Framework;
using TjZheng.Power.DataEntity;

namespace TjZheng.Power.Business
{
    public partial class BizPowerInfo
    {
        public override int DeleteIDString(string ids)
        {
            var objPowerInfoList = this.GetList(string.Format("Id in({0})", ids));
            int result = -1;
            if (objPowerInfoList.IsNull())
            {
                return result;
            }
            return (int)this.ExecuteTransation(() =>
            {
                string condition = string.Empty;
                List<long> powerIds = new List<long>();
                List<PowerInfo> objDeletePowerInfoList = null;
                foreach (var objPowerInfo in objPowerInfoList)
                {
                    condition = string.Format("IDPath like '{0}%'", objPowerInfo.IDPath);
                    objDeletePowerInfoList = this.GetList(string.Format("IDPath like '{0}%'", objPowerInfo.IDPath));
                    if (objDeletePowerInfoList.IsNoNull())
                    {
                        powerIds.AddRange(objDeletePowerInfoList.Select(c => c.Id));
                        result = this.Delete(condition);
                    }
                }
                if (powerIds.IsNoNull())
                {
                    BizGroupPowerInfo objBizGroupPowerInfo = new BizGroupPowerInfo();
                    condition = powerIds.Distinct().JoinComma().FormatSelf("PowerId in({0})");
                    result = objBizGroupPowerInfo.Delete(condition);
                }
                return result;
            });
        }
    }
}
